<?php

namespace app\admin\controller;

use app\app\controller\Project;
use app\app\model\ProjectGGKModel;
use app\app\model\ProjectKYPSModel;
use app\app\model\ProjectModel;
use app\app\model\ProjectRiskModel;
use app\app\model\ProjectXMHZModel;
use app\app\model\RandModel;
use app\BaseController;

class File extends BaseController
{
    public function kypfAdd()
    {
        $data = $this->request->param();
        $data['id'] = RandModel::randId();
        $type = $data['type'];
        unset($data['type']);

        //管控卡状态修改
        $this->changeProjectManage($type,$data['project_id']);

        ProjectKYPSModel::create($data);
        $this->success('success');
    }

    public function xmhzAdd()
    {
        $data = $this->request->param();
        $data['id'] = RandModel::randId();
        $type = $data['type'];
        unset($data['type']);
        //管控卡状态修改
        $this->changeProjectManage($type,$data['project_id']);
        ProjectXMHZModel::create($data);
        $this->success('success');
    }


    public function changeProjectManage($type,$project_id){
        $list = ProjectModel::where('link_project_id',$project_id)->select();
        foreach ($list as $key => $value){
            $res = ProjectGGKModel::where('ggk_id',$type)->where('project_id',$value['id'])->find();
            if ($res){
                $update['state'] = '已完成';
                $update['finsh_time'] = date('Y-m-d H:i:s', time());
                ProjectGGKModel::where('id',$res['id'])->update($update);
            }
        }
    }


}
